Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resolve): support resolving TS files by JS extension specifiers in JS files #18889

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sapphi-red
Copy link
Member

Description

#8993 (comment)

In the past meeting, we decided to support .js -> .ts resolving in JS files based on moduleResolution. We thought that TS requires moduleResolution to be set to Node16 or above at that time.
But it seems TypeScript allows importing TS files by JS extension specifiers regardless of moduleResolution.
https://stackblitz.com/edit/vitejs-vite-hvbhlg?file=tsconfig.json,sub1.ts,sub2.mts,main1.js&terminal=build
Surprisingly, this behavior seems to be there since TS 2.0 🫨(microsoft/TypeScript#8895, found the link in esbuild repo).

This PR allows the .js -> .ts resolving in JS files regardless of moduleResolution.

fixes #8993
refs #5510

@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label Dec 5, 2024
patak-dev
patak-dev previously approved these changes Dec 5, 2024
bluwy
bluwy previously approved these changes Dec 6, 2024
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for researching that. This makes the implementation a lot simpler.

@sapphi-red sapphi-red dismissed stale reviews from bluwy and patak-dev via 445e081 December 6, 2024 05:00
Copy link
Collaborator

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! There were people asking on Vitest too vitest-dev/vitest#5999

@sapphi-red
Copy link
Member Author

/ecosystem-ci run

Copy link

pkg-pr-new bot commented Dec 10, 2024

Open in Stackblitz

npm i https://pkg.pr.new/vite@18889

commit: 445e081

@vite-ecosystem-ci

This comment was marked as outdated.

@vite-ecosystem-ci
Copy link

@sapphi-red sapphi-red added this to the 6.1 milestone Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Typescript 4.7 "Node16" extension requirements
4 participants